"""Very simple Twitter-posting library.
Requires only default Python modules.
Very short."""

# credit : 
import urllib

class TwittApi :
	def __init__(self,username, password):
		self.username = username
		self.password = password
		pass

	def truncate(self,string,target):
		if len(string) > target:
			return string[:(target-3)] + "..."
		else:
			return string

	def squawk(self,message):
		"""Simple post-to-twitter function"""
		message = self.truncate(message,140) # trim message

		data = urllib.urlencode({"status" : message})
		res = urllib.urlopen("http://%s:%s@twitter.com/statuses/update.xml" % (self.username, self.password), data)

	def setAccount(self, username, password):
		self.username = username
		self.password = password

if __name__ == "__main__" :
	t = TwittApi()
	t.squawk("wearetherock","=v[ohv'9hk","The message to post (test script)")

